package handlers

import (
	"github.com/gin-gonic/gin"
	"go-tools/models"
)

func GetIdolsByName(c *gin.Context) {
	db := models.GetDB()

	name := c.Query("name")
	var idols []models.Idol

	// 查询数据库
	result := db.Where("value_cn LIKE ?", "%"+name+"%").Find(&idols)
	if result.Error != nil {
		c.JSON(500, gin.H{
			"error": result.Error.Error(),
		})
		return
	}

	// 返回查询结果
	c.JSON(200, gin.H{
		"data": idols,
	})
}
